<template>
	<view class="container">
		<view class="subsite-banner"><image src="https://www.fzftjc.com/static/rs/itorder/applet/breadcrumb-bg.jpg" mode="widthFix">
		<view class="subsite-caption">
			<view class="fz18">为千万家庭提供一站式基础建材服务</view>
		</view>
		</view>
		<!-- News -->
		<view class="subsite subsite-with-banner">
			<view class="subsite-heading">
				<view class="section-main-title fz18"><text>//</text>新闻资讯<text>//</text></view>
				<view class="subsite-tabs">
					<uni-segmented-control :current="current" :values="items" :style-type="styleType" @clickItem="onClickItem" />
				</view>
			</view>
			<view class="subsite-row">
				<view v-if="current === k" v-for="(v , k) in items">
					<navigator :url="'news-show?news_id='+value.id" class="news-item" hover-class="none" v-for="(value,index) in news">
						<view class="uni-flex">
							<view class="news-item-img">
								<image :src="value.thumb" mode="aspectFill"></image>
							</view>
							<view class="news-item-desc uni-flex-item">
								<view class="bold ellipsis">{{value.title}}</view>
								<view class="c-gray fz12 ellipsis-l2">{{value.description}}</view>
								<text class="fz10 c-gray9" >{{formatTime(value.inputtime,1)}}</text>
							</view>
						</view>
					</navigator>	
				</view>
			</view>
			<view class="flex-center">
				<uni-pagination :total="total" @change="next" :current="page" :pageSize="4" title="标题文字" />
			</view>
		</view>
		<!-- News end-->
		<!-- Footer -->
		<relation></relation>
		<!-- Footer end-->
		<u-tabbar></u-tabbar>
	</view>
</template>

<script>
	import relation from'../public/relation.vue';
	import base from '../../js/base.js';
	import app from '../../js/app.js';
	export default {
		components:{
			relation
		},
		data() {
			return {
				items: ['企业动态', '行业资讯'],
				current: 0,
				styleType: 'button',
				data:[],
				page:1,
				news:{},
				total:0
			}
		},
		mounted() {
			this.category();
		},
		methods: {
			next(e){
				var This = this;
				base.request({
					url:base.urltext('/itorder/info_port/news_list'),
					header:{ 'content-type': 'application/x-www-form-urlencoded' },
					data:{ page:e.current,catid:This.data[this.current].catid},
					success:function(res){
						if(res.data.success>0)
						{
							This.news = res.data.list;
							This.total = res.data.total;							
						}
					}
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为：' + e.detail.value)
				this.index = e.detail.value
			},
			formatTime:function(e,b=1){
				return base.formatTime(e,b);
			},
			onClickItem(e) {
				let This=this;
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
				base.request({
					url:base.urltext('/itorder/info_port/news_list'),
					header:{ 'content-type': 'application/x-www-form-urlencoded' },
					data:{ page:1,catid:This.data[e.currentIndex].catid},
					success:function(res){
						if(res.data.success>0)
						{
							This.news = res.data.list;
							This.total = res.data.total;
							//This.page =1;
							//This.total = 0;
							
						}
					}
				})
			},
			category(){
				let This = this;
				console.log(1);
				base.request({
					url:base.urltext('/itorder/info_port/news_classify'),
					success:function(res){
						var data = res.data.list;
						var arr = [];
						if(res.data.success>0)
						{
							for(var i in data)
							{
								arr.push(data[i].catname);
							}
							if(arr)
							{
								This.items=arr;
								This.data = data;
								This.onClickItem({currentIndex:0});
							}else{
								uni.showToast({
								    title: '无分类列表数据', mask: true, duration: 2500, icon: 'none'
								});
							}
						}
					}
				});
			}
		}
	}
</script>

<style>
	
</style>
